﻿using System;
using NL.ADA.ConfigService;
using System.ServiceModel;
using NL.ADA.Common;
namespace NL.ADA.ConfigProxy
{
    public class Gateway:IDisposable
    {
        private IConfigService _service;
        private ChannelFactory<IConfigService> _channelFactory; 
        public Gateway()
        {
            _channelFactory = new ChannelFactory<IConfigService>("WSHttpBinding_IConfigService"); //("[endpoint]")
            _service = _channelFactory.CreateChannel(); 
            
        }

        public int GetModeId(string mode)
        {
            return _service.GetModeIdByCode(mode);
        }

        public int GetApplicationId(string applicationCode)
        {
            return _service.GetApplicationIdByCode(applicationCode);
        }

        public DateTime GetServerModified(int appId,int modeId)
        {
            return _service.GetModified(appId, modeId);
        }
        
        public CustomConfigList GetAllConfigs(int appId,int modeId)
        {
            
            return _service.GetAllConfigs(appId,modeId);
        }

        #region IDisposable Members

        public void Dispose()
        {
            if (_channelFactory != null)
                _channelFactory = null;
        }

        #endregion
    }
}
